{% set pypi_name = 'freezer-api' %}
{% set source = fetch_source('https://tarballs.openstack.org/freezer-api/freezer-api-master.tar.gz') %}
{% set upstream_version = upstream_version() %}
{% set rpm_release = '1' %}
%if 0%{?rhel} || 0%{?fedora}
%global rdo 1
%endif
Name:           {{ py2name() }}
Version:        {{ py2rpmversion() }}
Release:        {{ py2rpmrelease() }}
Summary:        OpenStack Backup and Restore - API service
License:        {{ license('Apache-2.0') }}
Group:          Development/Languages/Python
URL:            https://docs.openstack.org/freezer
Source0:        {{ source|basename }}
Source1:        openstack-freezer-api.logrotate
BuildRequires:  openstack-macros
BuildRequires:  {{ py3('Paste') }}
BuildRequires:  {{ py3('PasteDeploy') }}
BuildRequires:  {{ py3('astroid') }}
BuildRequires:  {{ py3('elasticsearch') }}
BuildRequires:  {{ py3('falcon') }}
BuildRequires:  {{ py3('fixtures') }}
BuildRequires:  {{ py3('jsonschema') }}
BuildRequires:  {{ py3('keystonemiddleware') }}
BuildRequires:  {{ py3('mock') }}
BuildRequires:  {{ py3('oslo.config') }}
BuildRequires:  {{ py3('oslo.context') }}
BuildRequires:  {{ py3('oslo.db') }}
BuildRequires:  {{ py3('oslo.i18n') }}
BuildRequires:  {{ py3('oslo.log') }}
BuildRequires:  {{ py3('oslo.middleware') }}
BuildRequires:  {{ py3('oslo.policy') }}
BuildRequires:  {{ py3('oslo.serialization') }}
BuildRequires:  {{ py3('oslo.upgradecheck') }}
BuildRequires:  {{ py3('oslotest') }}
BuildRequires:  {{ py3('reno') }}
BuildRequires:  {{ py3('six') }}
BuildRequires:  {{ py3('stestr') }}
BuildRequires:  {{ py3('testresources') }}
BuildRequires:  {{ py3('testscenarios') }}
BuildRequires:  {{ py3('testtools') }}
Requires:       python3-{{ pypi_name }} = %{version}-%{release}
BuildArch:      noarch
%if 0%{?suse_version}
BuildRequires:  systemd-rpm-macros
Requires(pre):  pwdutils
%{?systemd_requires}
%endif
%if 0%{?rdo}
BuildRequires:  systemd
Requires(post): systemd
Requires(postun): systemd
Requires(pre):  shadow-utils
Requires(preun): systemd
%endif

%description
API service for OpenStack Freeze: an OpenStack Swift incremental
backup and restore automation tool for file system, MongoDB,
MySQL. LVM snapshot and encryption support.

%package -n     python3-{{ pypi_name }}
Summary:        Freezer API Python library
Group:          Development/Languages/Python
Requires:       {{ py3('Paste') }}
Requires:       {{ py3('PasteDeploy') }}
Requires:       {{ py3('elasticsearch') }}
Requires:       {{ py3('falcon') }}
Requires:       {{ py3('jsonschema') }}
Requires:       {{ py3('keystonemiddleware') }}
Requires:       {{ py3('oslo.config') }}
Requires:       {{ py3('oslo.context') }}
Requires:       {{ py3('oslo.db') }}
Requires:       {{ py3('oslo.i18n') }}
Requires:       {{ py3('oslo.log') }}
Requires:       {{ py3('oslo.middleware') }}
Requires:       {{ py3('oslo.policy') }}
Requires:       {{ py3('oslo.serialization') }}
Requires:       {{ py3('six') }}

%description -n python3-{{ pypi_name }}
API service for OpenStack Freezer: an OpenStack Swift incremental
backup and restore automation tool for file system, MongoDB,
MySQL. LVM snapshot and encryption support.

This package contains the Freezer API python libraries.

%package doc
Summary:        Documentation for OpenStack Backup Service
Group:          Documentation/HTML
BuildRequires:  fdupes
BuildRequires:  {{ py3('Sphinx') }}
#BuildRequires: {{ py3('openstackdocstheme') }}
BuildRequires:  {{ py3('os-api-ref') }}

%description doc
OpenStack Freezer API documentation.

This package contains the documentation

%prep
%autosetup -p1 -n {{ pypi_name }}-{{upstream_version}}
%py_req_cleanup

%build
%{py3_build}

PBR_VERSION=%{version} %sphinx_build -b html doc/source doc/build/html
# remove the Sphinx-build leftovers
rm -rf doc/build/html/.{doctrees,buildinfo}
%fdupes doc/build/html/

# config file generation
PYTHONPATH=. oslo-config-generator --config-file config-generator/freezer-api.conf \
    --output-file etc/freezer/freezer-api.conf.sample
# policy file generation
PYTHONPATH=. oslopolicy-sample-generator --config-file etc/freezer/freezer-policy-generator.conf \
    --output-file etc/freezer/freezer-api.policy.yaml

%install
%{py3_install}
install -d -m 755 %{buildroot}%{_sysconfdir}/freezer
install -d -m 755 %{buildroot}%{_sysconfdir}/freezer/freezer-api.conf.d/
install -d -m 755 %{buildroot}%{_localstatedir}/{lib,log}/freezer
install -p -D -m 640 etc/freezer/freezer-api.conf.sample %{buildroot}%{_sysconfdir}/freezer/freezer-api.conf
install -p -D -m 640 etc/freezer/freezer-api.policy.yaml %{buildroot}%{_sysconfdir}/freezer/policy.yaml
install -p -D -m 640 etc/freezer/freezer-paste.ini %{buildroot}%{_sysconfdir}/freezer/freezer-paste.ini
install -p -D -m 644 %{SOURCE1} %{buildroot}%{_sysconfdir}/logrotate.d/openstack-freezer-api

# remove duplicates
%fdupes %{buildroot}%{python3_sitelib}

%pre
%openstack_pre_user_group_create freezer freezer /sbin/nologin

%check
python3 -m stestr.cli run

%files
%license LICENSE
%doc README.rst
%{_bindir}/freezer-api
%{_bindir}/freezer-api-wsgi
%{_bindir}/freezer-manage
%{_bindir}/freezer-manager-status
%dir %attr(0750, root, freezer) %{_sysconfdir}/freezer/
%dir %attr(0750, root, freezer) %{_sysconfdir}/freezer/freezer-api.conf.d/
%config(noreplace) %attr(0640, root, freezer) %{_sysconfdir}/freezer/freezer-api.conf
%config(noreplace) %attr(0640, root, freezer) %{_sysconfdir}/freezer/freezer-paste.ini
%config(noreplace) %attr(0640, root, freezer) %{_sysconfdir}/freezer/policy.yaml
%config(noreplace) %{_sysconfdir}/logrotate.d/openstack-freezer-api
%dir %attr(0755, freezer, freezer) %{_localstatedir}/lib/freezer
%dir %attr(0750, freezer, freezer) %{_localstatedir}/log/freezer

%files -n python3-{{ pypi_name }}
%doc README.rst
%license LICENSE
%{python3_sitelib}/freezer_api/
%{python3_sitelib}/freezer_api*.egg-info

%files doc
%license LICENSE
%doc doc/build/html

%changelog
